/*
 * @Description:
 * @Author: 胡涛
 * @Date: 2023-09-11 14:32:47
 * @LastEditors: 胡涛
 * @LastEditTime: 2023-10-09 20:55:21
 */
import * as icons from "@ant-design/icons-vue/lib/icons";
import { h } from "vue";
import { toUpperCamelCaseName } from "./camel";

const iconKeys = Object.keys(icons);

/**
 *  根据图标名称获取图标组件
 * @param name
 * @returns
 */
export const getIconComponent = (
  name: string,
  type?: "Outlined" | "Filled"
) => {
  let comName = toUpperCamelCaseName(name);
  let suffix = type || "Outlined";
  if (comName.indexOf(suffix) == -1) {
    comName += suffix;
  }
  if (iconKeys.indexOf(comName) !== -1) {
    return h(icons[comName]);
  } else {
    return null;
  }
};
